package ecg.util;

import java.util.Calendar;

public class Time
{
	private Time()
	{
		super();
	}
	
	public static String getDateTime()
	{
		Calendar cal = Calendar.getInstance();
		String today = String.format("%04d-%02d-%02d %02d:%02d:%02d", cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
		
		return today;
	}
	
	public static String getDateTimeSerial()
	{
		Calendar cal = Calendar.getInstance();
		String today = String.format("%04d%02d%02d%02d%02d%02d", cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
		
		return today;
	}
	
	public static String getNumberByPattern(String pattern) {
		java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(
				pattern, java.util.Locale.KOREA);
		String dateString = formatter.format(new java.util.Date());
		return dateString;
	}


	public static String getYear() {
		return getNumberByPattern("yyyy");
	}
	
	public static String getYearMonthDayWithDash(){
		return getNumberByPattern("yyyy-MM-dd");
	}
	
	
	/**
	 * @param year
	 * @param month
	 * @return 해당 년, 월의 마지막 일자를 반환
	 */
	public static int getLastDay(String year, String month){
		Calendar cal = Calendar.getInstance();
		
		cal.set(Calendar.YEAR, Integer.parseInt(year));
		cal.set(Calendar.MONTH, Integer.parseInt(month) - 1);
		
		return cal.getActualMaximum(Calendar.DAY_OF_MONTH);
	}
}
